package org.msfj.generator;

import cn.hutool.core.date.DateUtil;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.InnerClass;
import org.mybatis.generator.internal.DefaultCommentGenerator;

/**
 * @Description:
 * @User: like
 * @Date: 2016/7/13 15:06
 * @Version: 1.0
 * @Created with IntelliJ IDEA.
 */
public class MyCommentGenerator extends DefaultCommentGenerator {

    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        if (introspectedColumn.getRemarks() != null && !introspectedColumn.getRemarks().equals("")) {
            field.addJavaDocLine("/**");
            field.addJavaDocLine(" * " + introspectedColumn.getRemarks());
            field.addJavaDocLine(" * ");
            field.addJavaDocLine("/* 数据库字段：" + introspectedColumn.getIntrospectedTable().getAliasedFullyQualifiedTableNameAtRuntime() + "." + introspectedColumn.getActualColumnName());
            addJavadocTag(field, false);
            field.addJavaDocLine(" */");
        }
    }

    @Override
    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
        StringBuilder sb = new StringBuilder();
        innerClass.addJavaDocLine("/**");
        innerClass.addJavaDocLine(" * @Description: " + introspectedTable.getRemarks());
        sb.append(" * @Author: like");
        sb.append(" * @Date: " + DateUtil.now());
        sb.append(" * @Version: 1.0");
        sb.append(" * @Created in idea by autoCode");
        innerClass.addJavaDocLine(sb.toString());
        this.addJavadocTag(innerClass, false);
        innerClass.addJavaDocLine(" */");
    }

}
